<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <title>酒精稀释计算器</title>
        <link rel="stylesheet" href="">
    </head>
    <body>
        <h1>酒精稀释计算器</h1>
        <input type="number" step="0.01" id="alcohol" placeholder="Alcohol %" value="95"><span>当前酒精度数</span><br>
        <input type="number" step="0.01" id="volume" placeholder="Volume (ml)" value="500"><span>当前酒精毫升</span><br>
        <input type="number" step="0.01" id="water" placeholder="Water (ml)" value="133.33" disabled><span>加水毫升</span><br>
        <input type="number" step="0.01" id="dilution" placeholder="Dilution %" value="75"><span>目标酒精度数</span><br>
        <input type="number" step="0.01" id="dilutionVolume" placeholder="Dilution Volume (ml)" value="633.33"><span>目标酒精毫升</span>
        <p>祝君好运</p>
        <script type="application/javascript" src="./alcoholDilutionCalculator.js"></script>
        <script>
            /** @type {HTMLInputElement}  */
            const alcohol = document.querySelector('#alcohol')
            /** @type {HTMLInputElement}  */
            const volume = document.querySelector('#volume')
            /** @type {HTMLInputElement}  */
            const water = document.querySelector('#water')
            /** @type {HTMLInputElement}  */
            const dilution = document.querySelector('#dilution')
            /** @type {HTMLInputElement}  */
            const dilutionVolume = document.querySelector('#dilutionVolume')
            const adc = ()=> {
                const result = alcoholDilutionCalculator(Number(alcohol.value) || 0, Number(volume.value) || 0, Number(dilution.value) || 0)
                water.value = result.waterMl.toString()
                dilutionVolume.value = result.targetMl.toString()
            }
            // 当 alcohol volume dilution 改变时触发
            alcohol.addEventListener("change", ()=>{
                adc()
            })
            volume.addEventListener("change", ()=>{
                adc()
            })
            dilution.addEventListener("change", ()=>{
                adc()
            })
            dilutionVolume.addEventListener("change", ()=>{
                const result = calculateSourceMl(Number(alcohol.value) || 0, Number(dilution.value) || 0, Number(dilutionVolume.value) || 0)
                volume.value = result.sourceMl.toString()
                water.value = result.waterMl.toString()
            })
        </script>
    </body>
</html>